<template>
	<view class="goods-style">
		<goodsList :goods="goods"></goodsList>
		<view class="isOver" v-if="flag" style="text-align: center;font-size: 30rpx;">------我是有底线的------</view>
	</view>
</template>

<script>
	import goodsList from "../../components/goos-list/goods-list.vue"
	export default {
		data() {
			return {
				page: 1,
				goods: [],
				flag: false,
				totalAll:1000
			}
		},
		components: {
			goodsList
		},
		onLoad() {
			this.getHotGoods()
		},
		onReachBottom() {
			if(this.goods.length >= this.totalAll){
				this.flag = true
			}
			this.page++
			this.getHotGoods()
		},
		onPullDownRefresh() {
			this.page = 1
			this.goods = []
			this.totalAll = 1000
			this.flag = false
			setTimeout(() => {
				this.getHotGoods(() => {
					uni.stopPullDownRefresh()
				})
			},1000)
		},
		methods: {
			async getHotGoods(fun) {
				const res = await this.$myRequest({
					url: "/home/data",
					data: {
						type: "sell",
						page: this.page
					}
				})
				if (res) {
					this.totalAll = res.data.data.total
					this.goods = [...this.goods, ...res.data.data.list]
				}
				fun && fun()
			},
		}
	}
</script>

<style>
	.goods-style {
		background: #eee;
	}
</style>
